#!/bin/bash

#! amount args
# ${_is_amount_arg} ${NARGS} min_equ max_equ
# if [ $? -ne 0 ]; then
#     plt_pause "from ${FNN}() :: ${_is_amount_arg} ${NARGS} min_equ:: be return 1"
#     return 1
# fi
#! normalize ptr_path -> absolut path
# ptr_path=$1
# ptr_path=$(${_abs_path} $PPWD "ptr_path") #ptr args
#! variables for cr_f_dir_insert_
# fn_name=$(${_prs_f} -n ${arg_path})
# root_path=$(${_prs_f} -d ${arg_path})
#! search in array
# [[ " ${arr[*]} " =~ " $1 " ]] && echo "true" || echo "false"
#! ${array[@]:1} all from 1 member arr

# echo -e "${GREEN}\${g_args[@]} = ${g_args[*]}${NORMAL}" #print variable
# echo -e "${GREEN}\${e_args[@]} = ${e_args[*]}${NORMAL}" #print variable
# echo -e "${GREEN}\${f_args[@]} = ${f_args[*]}${NORMAL}" #print variable
# echo -e "${GREEN}\${ARGS[@]} = ${ARGS[*]}${NORMAL}"     #print variable
# echo -e "${GREEN}\${NARGS} = ${NARGS}${NORMAL}"         #print variable
# echo -e "${GREEN}\${ARGS0} = ${ARGS0}${NORMAL}"         #print variable
# echo -e "${GREEN}\${ARGS1} = ${ARGS1}${NORMAL}"         #print variable
# echo -e "${GREEN}\${ARGS2} = ${ARGS2}${NORMAL}"         #print variable
# echo -e "${GREEN}\${PPWD} = ${PPWD}${NORMAL}"           #print variable

# echo -e "${GREEN}\${dir_fns_} = ${dir_fns_}${NORMAL}" #print variable

# echo -e "${GREEN}\${var_wrap_arr[@]} = ${var_wrap_arr[*]}${NORMAL}" #print variable
# echo -e "${GREEN}\${var_fn_arr[@]} = ${var_fn_arr[*]}${NORMAL}"     #print variable

# echo -e "${GREEN}\${arg_fn_arr[@]} = ${arg_fn_arr[*]}${NORMAL}"
# echo -e "${GREEN}\${env_fn_arr[@]} = ${env_fn_arr[*]}${NORMAL}"
# echo -e "${GREEN}\${pts_fn_arr[@]} = ${pts_fn_arr[*]}${NORMAL}"

# echo -e "${GREEN}\$val_ppr = $val_ppr${NORMAL}" #print variable

# echo -e "${GREEN}\$ratis = $ratis${NORMAL}" #print variable

# echo "that ${FNN}.sal"

#! every from list_strong_cntls by able
# list_strong_cntls=(?str_ ?del_ ?parr_)
# for item in "${list_strong_cntls[@]}"; do
#     echo -e "${GREEN}\$item = $item${NORMAL}" #print variable
#     echo "$(eval echo \$"$item")"
#     if [ -z "$(eval echo \$"$item")" ]; then
#         plt_info "from ${FNN}() :: $item is empty :: be return 1"
#         return 1
#     fi
# done

#! once dpl_ or bcp_ mast be able (0 1)
# sum_1=$((${dpl_:-0} + ${bcp_:-0}))
# echo -e "${GREEN}\$sum_1 = $sum_1${NORMAL}"

# if [ "${sum_1:-0}" -ne 1 ]; then
#     plt_info "from ${FNN}() once dpl_ or bcp_ mast be able :: be return 1"
#     return 1
# fi

#! see ${PATH_CURR_REPO}/NBash/_man/ptr/flow_1.sh
#? in nid allready be reseiving value from ppr_
#   eval val_ppr=\$"${ppr_}" # reseiving value from ppr_
#? use and assign new value to ppr_
#   eval ${ppr_}=$(any_fn ${val_ppr}) # use old value of ppr_ and assign new value to ppr_

#! in pts_fn_arr contane external idetificators (pointers)
# num=
# echo num>pts.list
# any_fn(){num=10}
# any_fn --_pts pts.list
# any_fn
# echo ${num}
# 10

#! cr fs cr_f_
# cr_f_ \
#     "$filename" \
#     --tml "${PATH_TML_DIR}/cr_shf_/shf.tml" \
#     --fi0 "${header}" --fr0 "{header}" \
#     --vi0 "$filename" --vr0 "{filename}"

#! cr fs standart
# "${_obs_quis_}" "$filename"
# "${_upg_path}" "$filename"

#! cr fs cr_f_dir_insert_
# ${_cr_f_dir_insert_} --name ${filename} --dir_insert ${PATH_INSERT_DIR}/obs_quis_

#! innerfns
# if [ -d "${sil_}/proc/fol_" ]; then

#     c_up "${sil_}/proc/fol_"

#     inner_fn_arr=()
#     dr2parr_ inner_fn_arr 3 "${sil_}/proc/fol_"

# else
#     plt_exit "in ${FNN} : NOT_DIR : '${sil_}/proc/fol_' return 1"
#     return 1
# fi

# for item6 in ${inner_fn_arr[@]}; do
#     echo -e "${GREEN}\$item6 = $item6${NORMAL}" #print variable

#     ${item6}

#     ret_nom=$?
#     if [ ${ret_nom} -eq 2 ]; then
#         return 0
#     fi
#     if [ ${ret_nom} -eq 3 ]; then
#         return 1
#     fi
#     echo -e "${GREEN}\$ret_nom = $ret_nom${NORMAL}" #print variable

# done

#?--------------------------------------------------------
#?---------------------------------------------
#?---------------------------------------

arg_mast_arr_1=("0" "-d" "-ne" "-n" "-e" "-pr" "-po")

if ! [[ "${arg_mast_arr_1[*]}" =~ "${ARGS0}" ]]; then
    plt_exit "in ${FNN} : ERR_ARG : '${ARGS0}' not from  ( 0 "-d" "-ne" "-n" "-e" "-pr" "-po" ) return 1"
    return 1
fi

arg_mast_arr_2=(-ff -dd -fd)

if ! [[ "${arg_mast_arr_2[*]}" =~ "${ARGS1}" ]]; then
    plt_exit "in ${FNN} : ERR_ARG : '${ARGS1}' not from  (-ff -dd -fd) return 1"
    return 1
fi

ptr_path="${ARGS2}"
ptr_path=$(${_abs_path} $PPWD "ptr_path") #ptr args

if ! [[ -d "${ptr_path}" ]]; then
    plt_exit "in ${FNN} : NOT_DIR : '${ptr_path}' return 1"
    return 1
fi
ARGS3="${ARGS[3]}"
# echo -e "${GREEN}\$ARGS3 = $ARGS3${NORMAL}" #print variable

dr2e_v2_recurce() {
    if [ -d "${ptr_path}/$item" ] && [ "${item:0:1}" != "_" ]; then
        ${_dr2e_} ${ARGS0} ${ARGS1} "${ptr_path}/$item" ${ARGS3}
    fi
}

if [ "0" == "${ARGS0}" ]; then

    if [ -n "${ARGS3}" ]; then

        for item in $(ls "${ptr_path}"); do
            # ls "$1" | IFS= read -r item ; do

            # [[ -e "$item" ]] || break
            if [[ ${ARGS1} == "-ff" ]]; then
                if [ -f "${ptr_path}/$item" ] && [ "${item:0:1}" != "_" ] && [ "$(prs_f -e "$item")" == "${ARGS3}" ]; then
                    echo "${ptr_path}/$item"
                fi
                dr2e_v2_recurce
            fi

            if [[ ${ARGS1} == "-dd" ]]; then
                if [ -d "${ptr_path}/$item" ] && [ "${item:0:1}" != "_" ] && [ "$(prs_f -e "$item")" == "${ARGS3}" ]; then
                    echo "${ptr_path}/$item"
                fi
                dr2e_v2_recurce
            fi

            if [[ ${ARGS1} == "-fd" ]]; then
                if ([ -d "${ptr_path}/$item" ] || [ -f "${ptr_path}/$item" ]) && [ "${item:0:1}" != "_" ] && [ "$(prs_f -e "$item")" == "${ARGS3}" ]; then
                    echo "${ptr_path}/$item"
                fi
                dr2e_v2_recurce
            fi
        done

    elif [ -z "${ARGS3}" ]; then

        for item in $(ls "${ptr_path}"); do
            # ls "$1" | IFS= read -r item ; do

            # [[ -e "$item" ]] || break
            if [[ "${ARGS1}" == "-ff" ]]; then
                if [ -f "${ptr_path}/$item" ] && [ "${item:0:1}" != "_" ]; then
                    echo "${ptr_path}/$item"
                fi
                dr2e_v2_recurce
            fi

            if [[ "${ARGS1}" == "-dd" ]]; then
                if [ -d "${ptr_path}/$item" ] && [ "${item:0:1}" != "_" ]; then
                    echo "${ptr_path}/$item"

                fi
                dr2e_v2_recurce
            fi

            if [[ "${ARGS1}" == "-fd" ]]; then
                if ([ -d "${ptr_path}/$item" ] || [ -f "${ptr_path}/$item" ]) && [ "${item:0:1}" != "_" ]; then
                    echo "${ptr_path}/$item"

                fi
                dr2e_v2_recurce
            fi

        done
    fi

else

    if [ -n "${ARGS3}" ]; then

        for item in $(ls "${ptr_path}"); do
            # ls "$1" | IFS= read -r item ; do

            # [[ -e "$item" ]] || break
            if [[ ${ARGS1} == "-ff" ]]; then
                if [ -f "${ptr_path}/$item" ] && [ "${item:0:1}" != "_" ] && [ "$(prs_f -e "$item")" == "${ARGS3}" ]; then
                    echo $(prs_f ${ARGS0} ${ptr_path}/$item)
                fi
                dr2e_v2_recurce
            fi

            if [[ ${ARGS1} == "-dd" ]]; then
                if [ -d "${ptr_path}/$item" ] && [ "${item:0:1}" != "_" ] && [ "$(prs_f -e "$item")" == "${ARGS3}" ]; then
                    echo $(prs_f ${ARGS0} ${ptr_path}/$item)
                fi
                dr2e_v2_recurce
            fi

            if [[ ${ARGS1} == "-fd" ]]; then
                if ([ -d "${ptr_path}/$item" ] || [ -f "${ptr_path}/$item" ]) && [ "${item:0:1}" != "_" ] && [ "$(prs_f -e "$item")" == "${ARGS3}" ]; then
                    echo $(prs_f ${ARGS0} ${ptr_path}/$item)

                fi
                dr2e_v2_recurce
            fi
        done 

    elif [ -z "${ARGS3}" ]; then

        for item in $(ls "${ptr_path}"); do
            # ls "$1" | IFS= read -r item ; do

            # [[ -e "$item" ]] || break
            if [[ "${ARGS1}" == "-ff" ]]; then
                if [ -f "${ptr_path}/$item" ] && [ "${item:0:1}" != "_" ]; then
                    echo $(prs_f ${ARGS0} ${ptr_path}/$item)
                fi
                dr2e_v2_recurce
            fi

            if [[ "${ARGS1}" == "-dd" ]]; then
                if [ -d "${ptr_path}/$item" ] && [ "${item:0:1}" != "_" ]; then
                    echo $(prs_f ${ARGS0} ${ptr_path}/$item)
                fi
                dr2e_v2_recurce
            fi

            if [[ "${ARGS1}" == "-fd" ]]; then
                if ([ -d "${ptr_path}/$item" ] || [ -f "${ptr_path}/$item" ]) && [ "${item:0:1}" != "_" ]; then
                    echo $(prs_f ${ARGS0} ${ptr_path}/$item)
                fi
                dr2e_v2_recurce
            fi
        done
    fi
fi

IFS=$' \t\n'

#{main_body_fn}

#?---------------------------------------
#?---------------------------------------------
#?--------------------------------------------------------
